# -*- coding: utf-8 -*-

# graphic-pppoe-client - Easy graphic networking manager
#
# Author: GoTLiuM InSPiRiT <gotlium@gmail.com>
#
# Copyright 2010, GoTLiuM InSPiRiT <gotlium@gmail.com>.
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2, as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranties of
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
# PURPOSE.  See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program.  If not, see <http://www.gnu.org/licenses/>.

from libraries.fs import DB_DIR
from libraries.sqlite import *

db = SQLite(DB_DIR)

def dbs(f):
	def fun(*args, **kwargs):
		db.connect()
		res = f(*args, **kwargs)
		db.disconnect()
		return res
	return fun

@dbs
def getConnectionById(id):
	result = db.select('connections', {'id': id})
	if result['num'] > 0:
		result = result['result']
	return result[0]

@dbs
def getIfnameByConnId(id):
	result = db.select('connections', {'id': id})
	if result['num'] > 0:
		return result['result'][0]['if_name']
	return None
